﻿using ItemsControlDemo01.Models;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;

namespace ItemsControlDemo01.ViewModels
{
    public class MainWindowVM : INotifyPropertyChanged
    {
        public Person MyProperty { get; set; }  = new Person();
        public ObservableCollection<Person> people { get; set; }   = new ObservableCollection<Person>();


        public MainWindowVM()
        {
            people.Add(
                new Person() { Name = "abv",Age = "20"}
            );
            people.Add(
                new Person() { Name = "dfdfd",Age = "88"}
            );

            Task.Factory.StartNew(() => {

                Thread.Sleep(3 * 1000);
                Application.Current.Dispatcher.Invoke(() =>
                {
                    people.Add(
                    new Person() { Name = "1111112232fdfdfg", Age = "200" });
                });
            });
        }

        public event PropertyChangedEventHandler? PropertyChanged;
    }
}
